#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cmath>
using namespace std;
const int N = 1010;
int cnt;
struct ss
{
	int yw;
	int sx;
	int yy;
}a[N];
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].yw >> a[i].sx >> a[i].yy;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if ((abs(a[i].yw - a[j].yw) <= 5) && (abs(a[i].sx - a[j].sx) <= 5) && (abs(a[i].yy - a[j].yy) <= 5))
			{
				if(abs(a[i].yw+a[i].sx+a[i].yy-a[j].yw-a[j].sx-a[j].yy)<=10)
					cnt++;
			}
		}
	}
	cout << cnt << endl;
}